import reqCategory from '@/api/category'

const state = {
    categoryInfo: {
        category1Id: '',
        category2Id: '',
        category3Id: '',
    },
    category1List: [],
    category2List: [],
    category3List: []
}

const mutations = {
    SET_CATEGORY1_LIST (state, category1List){
        state.category1List = category1List
    },
    SET_CATEGORY2_LIST (state, category2List){
        state.category2List = category2List
    },
    SET_CATEGORY3_LIST (state, category3List){
        state.category3List = category3List
    },
    SET_CATEGORYINFO (state, categoryInfo){
        state.categoryInfo = categoryInfo
    }
}

const actions = {
    async getCategory1List({commit}) {
        let res = await reqCategory.reqCategory1()
        commit('SET_CATEGORY1_LIST', res)
    },
    async getCategory2List({commit}, category1Id){
        let res = await reqCategory.reqCategory2(category1Id)
        commit('SET_CATEGORY2_LIST', res)
        commit('SET_CATEGORY3_LIST', [])
    },
    async getCategory3List({commit}, category2Id){
        let res = await reqCategory.reqCategory3(category2Id)
        commit('SET_CATEGORY3_LIST', res)
    },
    setCategoryInfo({commit}, categoryInfo){
        commit('SET_CATEGORYINFO', categoryInfo)
    }
}

const getters = {

}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}